﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;

namespace XDLPipeline
{
    /// <summary>
    /// Custom content pipeline processor derives from the built-in
    /// ModelProcessor. 
    /// </summary>
    [ContentProcessor(DisplayName="Blender DirectX Processor")]
    public class BlenderModelProcessor : ModelProcessor
    {
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            // directx files are left-handed, XNA is right-handed
            Matrix transform = new Matrix(
                1, 0, 0, 0,
                0, 1, 0, 0, 
                0, 0, -1.0f, 0,
                0, 0 ,0 ,1.0f);
            MeshHelper.TransformScene(input,transform);

            return base.Process(input, context);
        }

        /// <summary>
        /// Use the custom <see cref="NoMaterialProcessor"/>
        /// to convert all the materials on this model to null.
        /// </summary>
        protected override MaterialContent ConvertMaterial(MaterialContent material,
                                                         ContentProcessorContext context)
        {
            return context.Convert<MaterialContent, MaterialContent>(
                material,
                "NoMaterialProcessor");
        }
    }
}
